<?php
if(!check_manager_login()) exit('无权查看，请登录!');

require_once(LIB_PATH.DS.'upload.class.php');
//require_once(LIB_PATH.DS.'thumbnail.class.php');
require_once(MODEL_PATH.DS.'Brand.php');
$Brand = new Brand();

if(check_post()){
	$name = trim($_POST['name']);
	$sort = trim($_POST['sort_order']);
	$messages = array();
	$error = false;
	if(empty($name)){
		$error = true;
		$messages[] = "品牌名称不能为空!";
	}
	$Upload = new Upload('uploads/');
	$Upload->setMaxSize(512000);
	$Upload->move();
	$messages = $Upload->getMessages();
	$image = $Upload->getFilename();
	if((!$error)){
		$data = array(
			'name'=>$name,
			'sort_order'=>$sort,
			'image' =>$image[0],
		);
		$result = $Brand->addBrand($data);
		if($result){
			redirect('index.php?mod=brand&act=list','添加成功！');
		}
	}else{
		$messages[] = "添加失败!";
	}
}


include load_tpl('brand_add');
?>